VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "TestXMLNotification"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Private mProject As ProjectFixture
Private mFactory As ProjectFactory
Private mNotifier As XMLNotifier
Private mResult As New ResultPrimitive

Public Sub testProjectDynamically()
givenProject
whenProjectIsRun
thenXMLIs dummyProjectXML
End Sub

'' Helper methods to create XML
Private Function dummyProjectXML() As String
Dim p As Document
Set p = NewDocument("project")
p.createAttribute "name", "prjDummyTestProject"
p.createAttribute "classes", 2
p.createAttribute "methods", 5
p.createAttribute "asserts", 7
p.createAttribute "runtime", 9
populateClass1 p.addChild("class")
populateClass2 p.addChild("class")
dummyProjectXML = p.xml
End Function
Private Sub populateClass1(child As Document)
child.createAttribute "name", "Test1"
child.createAttribute "methods", 2
child.createAttribute "asserts", 3
child.createAttribute "runtime", 6
populateMethod child, "test1", 3, , True
populateMethod child, "Test2", 3
End Sub
Private Sub populateClass2(child As Document)
child.createAttribute "name", "Test2"
child.createAttribute "methods", 3
child.createAttribute "asserts", 4
child.createAttribute "runtime", 3
populateMethod child, "test1", 1, False
populateMethod child, "Test2", 1, False
populateMethod child, "test3", 1, False
End Sub
Private Sub populateMethod(parent As Document, name As String, runtime As Integer, Optional hasOthers As Boolean = True, Optional hasAssert As Boolean = False)
Dim child As Document
Set child = parent.addChild("method")
child.createAttribute "name", name
child.createAttribute "runtime", runtime
populateFineMethod child, "setup", Not hasOthers
If hasOthers Then
    populateFineMethod child, name, , hasAssert
    populateFineMethod child, "teardown"
End If
End Sub
Private Sub populateFineMethod(parent As Document, name As String, Optional addError1001 As Boolean = False, Optional hasAssert As Boolean = False)
Dim child As Document
Dim assertNode As Document
Set child = parent.addChild("finemethod")
child.createAttribute "name", name
child.createAttribute "runtime", 1
If addError1001 Then
    child.createAttribute "error", 1001
End If
If hasAssert Then
    Set assertNode = child.addChild("assert")
    assertNode.createAttribute "passed", True
    assertNode.createAttribute "message", "isTrue"
    assertNode.addChild("expected").addText "True"
    assertNode.addChild("actual").addText "True"
    assertNode.addText "Actual was true"
End If
End Sub

''
''
Private Sub givenProject()
Set mProject = mFactory.newProjectFixture(self)
End Sub
Private Sub whenProjectIsRun()
Set mNotifier = New XMLNotifier
Dim I As init
Set I = DummyAssert
I.init mResult
mResult.setNotification mNotifier
mProject.forward mNotifier
End Sub
Private Sub thenXMLIs(xml As String)
'Debug.Print xml
assert.equals mNotifier.xml, xml, "XML mismatch"
End Sub

''

''
'Self shunt as factory
Public Function newMethodTimer(forward As Object, host As Object) As Object
Dim caller As New MockMethodTimer
caller.init forward, host
Set newMethodTimer = caller
End Function


'OPTIONAL METHODS
Public Sub setup()
Set mFactory = New ProjectFactory
mFactory.init Me
End Sub

Public Function NumOfAsserts() As Long
NumOfAsserts = 1
End Function

